<%@page import="com.google.appengine.api.datastore.DatastoreService"%>
<%@page	import="com.google.appengine.api.datastore.DatastoreServiceFactory"%>
<%@page import="com.google.appengine.api.datastore.Entity"%>
<%@page	import="com.google.appengine.api.datastore.EntityNotFoundException"%>
<%@page import="com.google.appengine.api.datastore.FetchOptions"%>
<%@page import="com.google.appengine.api.datastore.Key"%>
<%@page import="com.google.appengine.api.datastore.KeyFactory"%>
<%@page import="com.google.appengine.api.datastore.Query"%>
<%@page	import="com.google.appengine.api.datastore.Query.FilterOperator"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%  
	DatastoreService d = DatastoreServiceFactory.getDatastoreService();

	Key Skey = KeyFactory.createKey("Students", "Students");
		Query Sq = new Query("Student", Skey).addFilter("studentId", Query.FilterOperator.EQUAL , String.valueOf(request.getParameter("sn"))  );
	List<Entity> Sl = d.prepare(Sq).asList(	FetchOptions.Builder.withDefaults());
	
	
	Query Cq = new Query("vak" , Sl.get(0).getKey());
	List<Entity> Cl = d.prepare(Cq).asList(	FetchOptions.Builder.withDefaults());
	
	
	Query Rq =  new Query("Result" , Sl.get(0).getKey()).addFilter("courseCode" , FilterOperator.EQUAL ,String.valueOf(request.getParameter("classes"))) ; 
	List<Entity> Rl = d.prepare(Rq).asList(FetchOptions.Builder.withDefaults());
	 
 
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Prestaties van student <%=Sl.get(0).getProperty("surName")%>, <%=Sl.get(0).getProperty("firstName")%></title>

<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
      google.load("visualization", "1", {packages:["corechart"]});
      google.setOnLoadCallback(drawChart);
      function drawChart() {
        var data = new google.visualization.DataTable();
        data.addColumn('string', 'periode');
        data.addColumn('number', 'cijfer');
        data.addRows([
        <%
        for (int i = 0 ; i  < Rl.size() ; i++) {          	        	
        		if (i == Rl.size()-1) {
        				out.println("['"+Rl.get(i).getProperty("Date")+"',"+Rl.get(i).getProperty("Grade")+"]");
                } else {
                	out.println("['"+Rl.get(i).getProperty("Date")+"',"+Rl.get(i).getProperty("Grade")+"],");
                }
        	}
        %>        	
          ]);

        var options = {
          width: 400, height: 240,
          title: 'student : <%=Sl.get(0).getProperty("studentId") %> , <%=Sl.get(0).getProperty("surName") %>, <%=Sl.get(0).getProperty("firstName") %> , <%=Rl.get(0).getProperty("courseCode") %>'
	
		};

		var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
		chart.draw(data, options);
	}
</script>


<script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">
      google.load("visualization", "1", {packages:["corechart"]});
      google.setOnLoadCallback(drawChart);
      function drawChart() {
        var data = new google.visualization.DataTable();
        data.addColumn('string', 'Year');
        data.addColumn('number', 'grades');
        data.addRows([
                      <%
                      for (int i = 0 ; i  < Rl.size() ; i++){         
                      	
                      	if(i == Rl.size()-1){
                      		out.println("['"+Rl.get(i).getProperty("Date")+"',"+Rl.get(i).getProperty("Grade")+"]");
                              	}else{out.println("['"+Rl.get(i).getProperty("Date")+"',"+Rl.get(i).getProperty("Grade")+"],");}
                      	}
                      %>     
        ]);

        var options = {
          width: 400, height: 240,
          title: 'Performance',
          vAxis: {title: 'grades',  titleTextStyle: {color: 'red'}}
        };

        var chart = new google.visualization.BarChart(document.getElementById('chart_div1'));
        chart.draw(data, options);
      }
    </script>
<link rel="stylesheet" type="text/css" href="/include/style/style.css" />
</head>
<body>
	<jsp:include page="include/header.jsp" />
	<br>
	<a href="javascript:history.go(-1)">&larr;Ga terug naar student/vak selectie</a>
	<h2><%=Sl.get(0).getProperty("surName") %>, <%=Sl.get(0).getProperty("firstName")%>	</h2>
	<div id="chart_div"></div>
	<div id="chart_div1"></div>
</body>
</html>